tools = dosbox nop.bat -conf neocs.conf -noconsole -exit -c "\tools
tasm = $(tools)\tasm
tcc = $(tools)\tcc
gcc = mingw32-gcc
make = mingw32-make
tlink = $(tools)\tlink
exe2bin = $(tools)\exe2bin
nasm = ..\tools\nasm
nasm_flag = -fbin -I ../include/

build : loader.bin

clean :
	del loader.bin
	del c.*
	del std*.txt
	del *.obj
	del *.o
	del *.d

loader.bin : loader.s c.bin
	$(nasm) $(nasm_flag) loader.s -o loader.bin

cfiles = loader.c vsprintf.c

%.d: %.c
	@echo generate $@
	@$(gcc) -M -Iinclude -o $@.aa $<
	@..\tools\sed "s,\($*\)\.o[ :]*,\1.obj: ,g" < $@.aa > $@
	@del $@.aa
	@echo 	$(tcc) -c -mt -K -Iinclude $< > a.txt" >> $@
	@echo 	@echo ===================================================>> $@
	@echo 	@type a.txt>> $@
	@echo 	@echo ===================================================>> $@
	@echo 	@del a.txt>> $@

$(cfiles:.c.obj)%.obj: %.d
	mingw32-make -f $<

asmfiles = stub.asm n_scopy.asm h_ldiv.asm

$(asmfiles:.asm=.obj): %.obj: %.asm
	$(tasm) /z /ml /D__TINY__ $< $@ > a.txt"
	@echo ===================================================
	@type a.txt
	@echo ===================================================
	@del a.txt	

c.exe : $(asmfiles:.asm=.obj) $(cfiles:.c=.obj)
	$(tlink) /n $^, $@ > a.txt"
	@echo ===================================================
	@type a.txt
	@echo ===================================================
	@del a.txt

c.bin : c.exe
	$(exe2bin) $^ $@ > a.txt"
	@echo ===================================================
	@type a.txt
	@echo ===================================================
	@del a.txt
